<template>
  <el-row>
    <!-- 左边 -->
    <el-col :span="18">
      <i class="el-icon-s-home"></i>
      <span>{{item.name}}</span>
    </el-col>
    <!-- 右边 -->
    <el-col :span="6" style="text-align:right" class="right-col">
      <span>{{item.manager}}</span>
      <el-dropdown @command='mycommand'>
        <span class="el-dropdown-link">
          操作<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command='add'>添加子部门</el-dropdown-item>
          <el-dropdown-item command='edit' v-if="!item.isHead">查看部门</el-dropdown-item>
          <el-dropdown-item command='del' v-if="!item.isHead">删除部门</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from '@/api/departments'
export default {
    name:'tree-tools',
    props:['item'],
    methods:{
      mycommand(command){
        if(command == 'add'){
          //新增数据
          this.$emit('addDepartments',this.item.id)
        }else if (command == 'edit'){
          //查看数据
          this.$emit('editDepartments',this.item.id)
        }else if(command == 'del'){
          //删除数据
          // console.log('del');
          // console.log(this.item);
          this.$confirm('是否删除部门','警告').then(async ()=>{
            let res = await delDepartments(this.item.id)
            this.$message.success(res)
            this.$emit('resData');
          }).catch(()=>{console.log('取消成功');})
        }
      }
    }
}
</script>

<style></style>
